package com.elm.business.controller;


import com.elm.business.pojo.Business;
import com.elm.business.service.BusinessService;
import com.elm.common.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/business")
public class BusinessController {


    @Autowired
    private BusinessService businessService;

    @GetMapping("/listByOrderTypeId")
    public Result<List<Business>> listBusinessByOrderTypeId(@RequestParam Integer orderTypeId){
        List<Business> list=businessService.listBusinessByOrderTypeId(orderTypeId);
        if(list.size()!=0){
            return Result.success(list);
        }
        return Result.error("不存在该商家");

    }


    @GetMapping("/getById")
    public Result<Business> getBusinessById(@RequestParam Integer businessId){
        Business business=businessService.getBusinessById(businessId);
        if (business!=null){
            return Result.success(business);
        }
        return Result.error("不存在该商家");
    }

    @GetMapping("/list")
    public Result<List<Business>> list(){
        List<Business> list=businessService.list();
        return Result.success(list);
    }


}
